﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using MacViet.DataBaseAPI;


public partial class Control_User_Inventory : System.Web.UI.UserControl
{
   // int accid = 1;
    protected void Page_Load(object sender, EventArgs e)
    {
       // view product type to dropdownlist

        if (!IsPostBack)
        {
            try
            {
                int accid = int.Parse(Session["ACC_ID"].ToString());
                 //Session["ACC_ID"];
                PRODUCT_TYPESDataAPI product_type = new PRODUCT_TYPESDataAPI();
                DataTable dt_protype = product_type.GetPRO_TYPE_NAME_ACCID(accid);

                DDProType.DataSource = dt_protype; //set DataSource property of DropDownList

                DDProType.DataTextField = dt_protype.Columns[1].ToString(); //set DataTextField to first column(countryColumn) of dt

                DDProType.DataValueField = dt_protype.Columns[0].ToString(); //set DataTextField to second column (capitalColumn) of dt

                DDProType.DataBind(); //bind data to DropDownList
                //-------------------------------------------------------
                int proid = Convert.ToInt32(DDProType.SelectedValue);

                PRODUCTSDataAPI product = new PRODUCTSDataAPI();
                DataTable dt_pro = product.getPRODUCTS_GetPRO_NAME_By_Pro_ACC(proid, accid);
                if (dt_pro == null)
                {
                    DDProName.Text = "";
                }

                else
                {
                    DDProName.DataSource = dt_pro; //set DataSource property of DropDownList

                    DDProName.DataTextField = dt_pro.Columns[1].ToString(); //set DataTextField to first column(countryColumn) of dt

                    DDProName.DataValueField = dt_pro.Columns[0].ToString(); //set DataTextField to second column (capitalColumn) of dt

                    DDProName.DataBind(); //bind data to DropDownList
                }
                //-----------------------------------
                int protypeid = Convert.ToInt32(DDProType.SelectedValue);
                DataTable dt_pro_quantity = product.getPRODUCTS_GetPRO_QUANTITY_By_Pro_ACC(protypeid, proid, accid);

                if (dt_pro_quantity == null)
                {
                    lblQuantity.Text = "";
                }
                else
                {
                    lblQuantity.Text = dt_pro_quantity.Rows[0][1].ToString();
                }
            }


            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
    protected void DDProName_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            int accid = int.Parse(Session["ACC_ID"].ToString());
            if (DDProName.SelectedValue == null)
            {
                DDProName.Text = "";
            } 
            int protypeid = Convert.ToInt32(DDProType.SelectedValue);
            int proid = Convert.ToInt32(DDProName.SelectedValue);
            PRODUCTSDataAPI product = new PRODUCTSDataAPI();
            DataTable dt_pro = product.getPRODUCTS_GetPRO_QUANTITY_By_Pro_ACC(protypeid, proid, accid); ;
            if (dt_pro == null)
            {
                lblQuantity.Text = "";
            }
            else {

                lblQuantity.Text = dt_pro.Rows[0][1].ToString();
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }

    }
    protected void DDProType_SelectedIndexChanged(object sender, EventArgs e)
    {
       
            try
            {
                int accid = int.Parse(Session["ACC_ID"].ToString());
                int protypeid = Convert.ToInt32(DDProType.SelectedValue);

                PRODUCTSDataAPI product = new PRODUCTSDataAPI();
                DataTable dt_pro = product.getPRODUCTS_GetPRO_NAME_By_Pro_ACC(protypeid, accid);

                if (dt_pro == null)
                {
                    DataTable name = new DataTable();
                    DDProName.DataSource = name;
                    DDProName.DataTextField = "";
                    DDProName.DataValueField = "";
                    DDProName.DataBind();
                    DDProName.Text = "";
                   // DDProName.Text="";
                    lblQuantity.Text = "";
                }
                else
                {
                    DDProName.DataSource = dt_pro; //set DataSource property of DropDownList

                    DDProName.DataTextField = dt_pro.Columns[1].ToString(); //set DataTextField to first column(countryColumn) of dt

                    DDProName.DataValueField = dt_pro.Columns[0].ToString(); //set DataTextField to second column (capitalColumn) of dt

                    DDProName.DataBind();

                    int protype = Convert.ToInt32(DDProType.SelectedValue);
                    int proid = Convert.ToInt32(DDProName.SelectedValue);

                    DataTable dt_quantity = product.getPRODUCTS_GetPRO_QUANTITY_By_Pro_ACC(protype, proid, accid); ;
                    if (dt_quantity == null)
                    {
                        lblQuantity.Text = "";
                    }
                    else
                    {

                        lblQuantity.Text = dt_quantity.Rows[0][1].ToString();
                    }
                }  //bind data to DropDownList
            }


            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
 